window.onload=function(){	
	$(".payList > a").on('click',function(){
		if($(".numberInt").val()>0){
			event.preventDefault();
			hint('您已经输入了购买量，请点击"支付"');
		}else{
			var $this=$(this);
			$this.toggleClass('pActive').siblings().removeClass('pActive');
		}
	})
	function onBridgeReady(data){
	   WeixinJSBridge.invoke(
	       'getBrandWCPayRequest', {
	           "appId":data.appId,     //公众号名称，由商户传入     
	           "timeStamp":data.timeStamp,         //时间戳，自1970年以来的秒数     
	           "nonceStr":data.nonceStr, //随机串     
	           "package":data.package,     
	           "signType":data.signType,         //微信签名方式：     
	           "paySign":data.paySign //微信签名 
	       }
	   	)
	}

	$(".payBtn").click(function(e){
		if($(".recharge_mode").val()==2||$(".recharge_mode").val()==0){
			var Money=0,Flow=0;
			var moneyVal=$(".numberInt").val();
			if(!$(".payList > a").hasClass("pActive")&moneyVal==""){
				hint("请选择续费项！");
				e.preventDefault();
			}else{
				if(moneyVal==""){
					Money=$(".pActive").children("span").eq(0).html();
					Flow=$(".pActive").children("span").eq(1).html();
				}else{
					var reg =/^[0-9]*$/;
					if(!reg.test(moneyVal)){
						hint("请输入正整数！");
						moneyVal="";
					}else if(hint==0){
						hint("请输入正整数！");
						moneyVal="";
					}else{
						Money=moneyVal*100;
						Flow=$(".fluxBox").html();
					}
				}
				$.ajax({
					url:"/api/device/pay",
					type:"post",
					dataType:"json",
					data:{
						money:Money,
						flow:Flow,
					},
					success:function(data){
						if(data.status.errCode == 0){
							if (typeof WeixinJSBridge == "undefined"){
							   if( document.addEventListener ){
							       document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
							   }else if (document.attachEvent){
							       document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
							       document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
							   }
							}else{
							   onBridgeReady(data.data);
							}
						}
						else{
							hint(data.status.message);
						}
					}
				});
			}
		}else{
			hint("套餐模式续费请到经销处续费！");
			e.preventDefault();
		}
		
	});
}